<template>
    <div class="content checkreg-page">
        <section>
            <div class="clearfix">
                <h3 class="form-title f-fl">基本信息</h3>
                <div class="form-btns f-fr">
                    <Button type="primary" size="small" :disabled="disabledBtn" @click="submitSave" :loading="sbLoading">保存</Button>
                    <Button type="primary" size="small" :disabled="disabledBtn" @click="confirmSendSingleWindow(0)" :loading="sendLoading && sendType === 0">导入单一窗口</Button>
                    <Button type="primary" size="small" :disabled="disabledBtn" @click="confirmSendSingleWindow(1)" :loading="sendLoading && sendType === 1">导入并申报</Button>
                    <Button
                        type="primary"
                        size="small"
                        @click="openImportModal"
                        :disabled="disabledBtn"
                    >
                        Excel导入
                    </Button>
                    <Button type="primary" size="small" :loading="cpLoading" @click="copyInvt" :disabled="!form.invtId">复制</Button>
                    <Button type="primary" size="small" @click="printInvt(form.invtId)" :disabled="!form.invtId">打印</Button>
                    <Button @click="cancel" size="small">返回</Button>
                </div>
            </div>
            <Form id="base_form" ref="baseForm" :model="form" :rules="rules" class="declare-form" :show-message="false">
                <Row>
                    <iCol span="4">
                        <div class="form-label">委托单位</div>
                    </iCol>
                    <iCol span="3">
                        <RemoteSearch
                            :disabled="disabledBtn"
                            size="small"
                            v-model="form.custId"
                            :list="custList"
                            keywordFiled="custName"
                            valueField="custId"
                            :labelFieldList="['custId', 'custName']"
                        >
                        </RemoteSearch>
                    </iCol>
                    <iCol span="2">
                        <div class="form-label">预录入统一编号</div>
                    </iCol>
                    <iCol span="4">
                        <FormItem prop="seqNo">
                            <Input size="small" v-model="form.seqNo" disabled></Input>
                        </FormItem>
                    </iCol>
                    <iCol span="2">
                        <div class="form-label">清单编号</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="bondInvtNo">
                            <Input size="small" v-model="form.bondInvtNo" disabled></Input>
                        </FormItem>
                    </iCol>
                </Row>
                <!-- 4 3 5 5 4 3  -->
                <Row>
                    <iCol span="4">
                        <div class="form-label required">业务类型</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="sysId">
                            <RemoteSearch
                                :disabled="disabledBtn"
                                class="required-input-bg"
                                size="small"
                                :title="!formErr.sysId?'':formErr.sysId"
                                v-model="form.sysId"
                                :list="businessType"
                                keywordFiled="label"
                                valueField="value"
                                :labelFieldList="['value', 'label']"
                            >
                            </RemoteSearch>
                        </FormItem>
                    </iCol>
                    <iCol span="2">
                        <div class="form-label required">进出类别</div>
                    </iCol>
                    <iCol span="4">
                        <FormItem prop="impexpMarkcd">
                            <RemoteSearch
                                class="required-input-bg"
                                :disabled="disabledImpexpMarkcd || disabledBtn"
                                size="small"
                                :title="!formErr.impexpMarkcd?'':formErr.impexpMarkcd"
                                v-model="form.impexpMarkcd"
                                :list="inOutType"
                                keywordFiled="label"
                                valueField="value"
                                :labelFieldList="['value', 'label']"
                                @click.native="handleImpexpMarkcdClick"
                            >
                            </RemoteSearch>
                        </FormItem>
                    </iCol>
                    <iCol span="2">
                        <div class="form-label required">清单类型</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="invtType">
                            <RemoteSearch
                                class="required-input-bg"
                                :disabled="disabledBtn"
                                size="small"
                                :title="!formErr.invtType?'':formErr.invtType"
                                v-model="form.invtType"
                                :list="invtTypeList"
                                keywordFiled="label"
                                valueField="value"
                                :labelFieldList="['value', 'label']"
                            >
                            </RemoteSearch>
                        </FormItem>
                    </iCol>
                    <iCol span="3">
                        <div class="form-label required">手(账)册编号</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="putrecNo">
                            <Input
                                :disabled="disabledBtn"
                                :title="!formErr.putrecNo?'':formErr.putrecNo"
                                size="small"
                                class="required-input-bg"
                                :maxlength="12"
                                v-model.trim="form.putrecNo"
                            >
                            </Input>
                        </FormItem>
                    </iCol>
                </Row>
                <Row>
                    <iCol span="4">
                        <div class="form-label required">经营单位</div>
                    </iCol>
                    <iCol span="5">
                        <FormItem prop="bizopEtpsno">
                            <RemoteInput
                                :title="formErr.bizopEtpsno"
                                placeholder="经营单位编码"
                                :disabled="disabledBtn"
                                size="small"
                                class="required-input-bg"
                                label-in-value
                                :maxlength="10"
                                valueKey="operatorId"
                                labelKey="operatorCode"
                                :label="form.bizopEtpsno"
                                :displayField="['operatorCode']"
                                :remoteMethod="handleSearchBizopCode"
                                @change="handleBizopChange($event, 'bizopEtpsno')"
                                @get-query-name="v=>form.bizopEtpsno = v"
                            ></RemoteInput>
                        </FormItem>
                    </iCol>
                    <iCol span="6">
                        <FormItem prop="bizopEtpsSccd">
                            <RemoteInput
                                :disabled="disabledBtn"
                                :title="!formErr.bizopEtpsSccd?'':formErr.bizopEtpsSccd"
                                size="small"
                                class="required-input-bg"
                                placeholder="经营单位社会信用代码"
                                label-in-value
                                :maxlength="18"
                                valueKey="operatorId"
                                labelKey="coScc"
                                :label="form.bizopEtpsSccd"
                                :displayField="['coScc']"
                                :remoteMethod="handleSearchBizopCoScc"
                                @change="handleBizopChange($event, 'bizopEtpsSccd')"
                                @get-query-name="v=>form.bizopEtpsSccd = v"
                            ></RemoteInput>
                        </FormItem>
                    </iCol>
                    <iCol span="9">
                        <FormItem prop="bizopEtpsNm">
                            <RemoteInput
                                :disabled="disabledBtn"
                                placeholder="经营单位名称"
                                :title="formErr.bizopEtpsNm"
                                size="small"
                                placement="bottom-end"
                                class="required-input-bg"
                                label-in-value
                                :maxlength="70"
                                valueKey="operatorId"
                                labelKey="operatorName"
                                :label="form.bizopEtpsNm"
                                :displayField="['operatorName']"
                                :remoteMethod="handleSearchBizopName"
                                @change="handleBizopChange($event, 'bizopEtpsNm')"
                                @get-query-name="v=>form.bizopEtpsNm = v"
                            ></RemoteInput>
                        </FormItem>
                    </iCol>
                </Row>
                <Row>
                    <iCol span="4">
                        <div class="form-label required">加工单位</div>
                    </iCol>
                    <iCol span="5">
                        <FormItem prop="rcvgdEtpsno">
                            <RemoteInput
                                :disabled="disabledBtn"
                                :title="formErr.rcvgdEtpsno"
                                placeholder="加工单位编码"
                                size="small"
                                class="required-input-bg"
                                label-in-value
                                :maxlength="10"
                                valueKey="operatorId"
                                labelKey="operatorCode"
                                :label="form.rcvgdEtpsno"
                                :displayField="['operatorCode']"
                                :remoteMethod="handleSearchBizopCode"
                                @change="handleRcvgdChange($event, 'rcvgdEtpsno')"
                                @get-query-name="v=>form.rcvgdEtpsno = v"
                            ></RemoteInput>
                        </FormItem>
                    </iCol>
                    <iCol span="6">
                        <FormItem prop="rvsngdEtpsSccd">
                            <RemoteInput
                                :disabled="disabledBtn"
                                :title="formErr.rvsngdEtpsSccd"
                                placeholder="加工单位社会信用代码"
                                size="small"
                                class="required-input-bg"
                                label-in-value
                                :maxlength="18"
                                valueKey="operatorId"
                                labelKey="coScc"
                                :label="form.rvsngdEtpsSccd"
                                :displayField="['coScc']"
                                :remoteMethod="handleSearchBizopCoScc"
                                @change="handleRcvgdChange($event, 'rvsngdEtpsSccd')"
                                @get-query-name="v=>form.rvsngdEtpsSccd = v"
                            ></RemoteInput>
                        </FormItem>
                    </iCol>
                    <iCol span="9">
                        <FormItem prop="rcvgdEtpsNm">
                            <RemoteInput
                                :disabled="disabledBtn"
                                :title="formErr.rcvgdEtpsNm"
                                size="small"
                                placeholder="加工单位名称"
                                placement="bottom-end"
                                class="required-input-bg"
                                label-in-value
                                :maxlength="70"
                                valueKey="operatorId"
                                labelKey="operatorName"
                                :label="form.rcvgdEtpsNm"
                                :displayField="['operatorName']"
                                :remoteMethod="handleSearchBizopName"
                                @change="handleRcvgdChange($event, 'rcvgdEtpsNm')"
                                @get-query-name="v=>form.rcvgdEtpsNm = v"
                            ></RemoteInput>
                        </FormItem>
                    </iCol>
                </Row>
                <Row>
                    <iCol span="4">
                        <div class="form-label required">申报单位</div>
                    </iCol>
                    <iCol span="5">
                        <FormItem prop="dclEtpsno">
                            <Input
                                :disabled="disabledBtn"
                                class="required-input-bg"
                                size="small"
                                placeholder="申报单位编码"
                                :title="formErr.dclEtpsno"
                                v-model="form.dclEtpsno"
                                :maxlength="10"
                            />
                        </FormItem>
                    </iCol>
                    <iCol span="6">
                        <FormItem prop="dclEtpsSccd">
                            <Input
                                :disabled="disabledBtn"
                                size="small"
                                placeholder="申报单位社会信用代码"
                                v-model="form.dclEtpsSccd"
                                :maxlength="18"
                            />
                        </FormItem>
                    </iCol>
                    <iCol span="9">
                        <FormItem prop="dclEtpsNm">
                            <Input
                                :disabled="disabledBtn"
                                :title="formErr.dclEtpsNm"
                                placeholder="申报单位名称"
                                :maxlength="70"
                                class="required-input-bg"
                                size="small"
                                v-model="form.dclEtpsNm"
                            />
                        </FormItem>
                    </iCol>
                </Row>
                <Row>
                    <iCol span="4">
                        <div class="form-label required">录入单位</div>
                    </iCol>
                    <iCol span="5">
                        <FormItem prop="inputCode">
                            <Input
                                :disabled="disabledBtn"
                                class="required-input-bg"
                                placeholder="录入单位编码"
                                size="small"
                                :maxlength="10"
                                :title="formErr.inputCode"
                                v-model="form.inputCode"
                            />
                        </FormItem>
                    </iCol>
                    <iCol span="6">
                        <FormItem prop="inputCreditCode">
                            <Input
                                :disabled="disabledBtn"
                                placeholder="录入单位社会信用代码"
                                size="small"
                                :maxlength="18"
                                v-model="form.inputCreditCode"
                            />
                        </FormItem>
                    </iCol>
                    <iCol span="9">
                        <FormItem prop="inputName">
                            <Input
                                :disabled="disabledBtn"
                                class="required-input-bg"
                                placeholder="录入单位名称"
                                :maxlength="70"
                                size="small"
                                v-model="form.inputName"
                                :title="formErr.inputName"
                            />
                        </FormItem>
                    </iCol>
                </Row>
                <Row>
                    <iCol span="4">
                        <div class="form-label">企业内部编号</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="etpsInnerInvtNo">
                            <Input :disabled="disabledBtn" size="small" v-model="form.etpsInnerInvtNo" @on-blur="etpsNo = form.etpsInnerInvtNo"></Input>
                        </FormItem>
                    </iCol>
                    <iCol span="2">
                        <div class="form-label required">录入日期</div>
                    </iCol>
                    <iCol span="4">
                        <FormItem prop="inputTime">
                            <DatePicker
                                :disabled="disabledBtn"
                                :title="!formErr.inputTime?'':formErr.inputTime"
                                class="required-input-bg"
                                size="small"
                                type="date"
                                placement="bottom-end"
                                placeholder="请选择录入日期"
                                :value="form.inputTime"
                                @on-change="handleDateChange($event, 'inputTime')"
                            ></DatePicker>
                        </FormItem>
                    </iCol>
                    <iCol span="2">
                        <div class="form-label">清单申报日期</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="invtDclTime">
                            <DatePicker
                                :disabled="disabledBtn"
                                size="small"
                                type="date"
                                placement="bottom-end"
                                placeholder="请选择申报日期"
                                :value="form.invtDclTime"
                                @on-change="handleDateChange($event, 'invtDclTime')"
                            ></DatePicker>
                        </FormItem>
                    </iCol>
                    <iCol span="3">
                        <div class="form-label required">料件、成品标志</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="mtpckEndprdMarkcd">
                            <RemoteSearch
                                :disabled="disabledBtn"
                                class="required-input-bg"
                                size="small"
                                :title="!formErr.mtpckEndprdMarkcd?'':formErr.mtpckEndprdMarkcd"
                                v-model="form.mtpckEndprdMarkcd"
                                :list="MFProductMarkList"
                                keywordFiled="label"
                                valueField="value"
                                :labelFieldList="['value', 'label']"
                            >
                            </RemoteSearch>
                        </FormItem>
                    </iCol>
                </Row>
                <Row>

                    <iCol span="4">
                        <div class="form-label required">监管方式</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="supvModecd">
                            <RemoteSearch
                                :disabled="disabledBtn"
                                class="required-input-bg"
                                size="small"
                                :title="!formErr.mtpckEndprdMarkcd?'':formErr.mtpckEndprdMarkcd"
                                v-model="form.supvModecd"
                                :list="tradeModeList"
                                keywordFiled="shortName"
                                valueField="dataCode"
                                :labelFieldList="['dataCode', 'shortName']"
                                :secondLabels="['dataSecondType', 'dataThirdType']"
                            >
                            </RemoteSearch>
                        </FormItem>
                    </iCol>
                    <iCol span="2">
                        <div class="form-label required">运输方式</div>
                    </iCol>
                    <iCol span="4">
                        <FormItem prop="trspModecd">
                            <RemoteSearch
                                :disabled="disabledBtn"
                                class="required-input-bg"
                                size="small"
                                placement="bottom-end"
                                :title="!formErr.mtpckEndprdMarkcd?'':formErr.mtpckEndprdMarkcd"
                                v-model="form.trspModecd"
                                :list="trafModeList"
                                keywordFiled="shortName"
                                valueField="dataCode"
                                :labelFieldList="['dataCode', 'shortName']"
                                :secondLabels="['dataSecondType', 'dataThirdType']"
                            >
                            </RemoteSearch>
                        </FormItem>
                    </iCol>
                    <iCol span="2">
                        <div class="form-label required">{{impexpPortcdLabel}}</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="impexpPortcd">
                            <RemoteSearch
                                :disabled="disabledBtn"
                                class="required-input-bg"
                                size="small"
                                :title="!formErr.impexpPortcd?'':formErr.impexpPortcd"
                                v-model="form.impexpPortcd"
                                :list="this.customsCodeList"
                                keywordFiled="shortName"
                                valueField="dataCode"
                                :labelFieldList="['dataCode', 'shortName']"
                            >
                            </RemoteSearch>
                        </FormItem>
                    </iCol>
                    <iCol span="3">
                        <div class="form-label required">主管海关</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="dclPlcCuscd">
                            <RemoteSearch
                                :disabled="disabledBtn"
                                class="required-input-bg"
                                size="small"
                                :title="!formErr.dclPlcCuscd?'':formErr.dclPlcCuscd"
                                v-model="form.dclPlcCuscd"
                                :list="this.customsCodeList"
                                keywordFiled="shortName"
                                valueField="dataCode"
                                :labelFieldList="['dataCode', 'shortName']"
                            >
                            </RemoteSearch>
                        </FormItem>
                    </iCol>
                </Row>
                <Row>
                    <iCol span="4">
                        <div class="form-label">清单进出卡口状态</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="invtIochkptStucd">
                            <Input size="small" v-model="form.invtIochkptStucd" disabled></Input>
                        </FormItem>
                    </iCol>
                    <iCol span="2">
                        <div class="form-label required">{{stshipTrsarvNatcdLabel}}(地区)</div>
                    </iCol>
                    <iCol span="4">
                        <FormItem prop="stshipTrsarvNatcd">
                            <RemoteSearch
                                :disabled="disabledBtn"
                                class="required-input-bg"
                                size="small"
                                placement="bottom-end"
                                :title="!formErr.stshipTrsarvNatcd?'':formErr.stshipTrsarvNatcd"
                                v-model="form.stshipTrsarvNatcd"
                                :list="this.regionData"
                                keywordFiled="shortName"
                                valueField="dataSecondType"
                                :labelFieldList="['dataSecondType','shortName']"
                            >
                            </RemoteSearch>
                        </FormItem>
                    </iCol>
                    <iCol span="2">
                        <div class="form-label">申报表编号</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="applyNo">
                            <Input size="small" v-model="form.applyNo" :disabled="disabledBtn"></Input>
                        </FormItem>
                    </iCol>
                    <iCol span="3">
                        <div class="form-label">流转类型</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="listType">
                            <RemoteSearch
                                :disabled="disabledBtn"
                                size="small"
                                v-model="form.listType"
                                :list="listTypeList"
                                keywordFiled="label"
                                valueField="value"
                                :labelFieldList="['value','label']"
                            >
                            </RemoteSearch>
                        </FormItem>
                    </iCol>
                </Row>
                <Row>
                    <iCol span="4">
                        <div class="form-label required">报关标志</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="dclcusFlag">
                            <RemoteSearch
                                :disabled="disabledBtn"
                                class="required-input-bg"
                                size="small"
                                :title="!formErr.dclcusFlag?'':formErr.dclcusFlag"
                                v-model="form.dclcusFlag"
                                :list="dclcusFlagType"
                                keywordFiled="label"
                                valueField="value"
                                :labelFieldList="['value','label']"
                            >
                            </RemoteSearch>
                        </FormItem>
                    </iCol>
                    <iCol span="2">
                        <div class="form-label">报关类型</div>
                    </iCol>
                    <iCol span="4">
                        <FormItem prop="dclcusTypecd">
                            <RemoteSearch
                                :disabled="disabledBtn"
                                size="small"
                                :title="formErr.dclcusTypecd"
                                v-model="form.dclcusTypecd"
                                :list="dclcusTypecdType"
                                keywordFiled="label"
                                valueField="value"
                                :labelFieldList="['value','label']"
                                placement="bottom-end"
                            >
                            </RemoteSearch>
                        </FormItem>
                    </iCol>
                    <iCol span="2">
                        <div class="form-label">报关单类型</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="decType">
                            <RemoteSearch
                                :disabled="disabledBtn"
                                size="small"
                                v-model="form.decType"
                                :list="this.typeData"
                                keywordFiled="shortName"
                                valueField="dataCode"
                                :labelFieldList="['dataCode','shortName']"
                            >
                            </RemoteSearch>
                        </FormItem>
                    </iCol>
                    <iCol span="3">
                        <div class="form-label">核扣标志</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="vrfdedMarkcdName">
                            <Input size="small" v-model="form.vrfdedMarkcdName" disabled></Input>
                        </FormItem>
                    </iCol>
                </Row>
                <Row>
                    <iCol span="4">
                        <div class="form-label">对应报关单编号</div>
                    </iCol>
                    <iCol span="20">
                        <FormItem prop="entryNo">
                            <Input size="small" v-model="form.entryNo" disabled></Input>
                        </FormItem>
                    </iCol>
                </Row>
                <Row>
                    <iCol span="4">
                        <div class="form-label">对应报关单申报单位</div>
                    </iCol>
                    <iCol span="5">
                        <FormItem prop="corrEntryDclEtpsNo">
                            <Input
                                size="small"
                                placeholder="对应报关单申报单位编码"
                                v-model="form.corrEntryDclEtpsNo"
                                :maxlength="10"
                                :title="formErr.corrEntryDclEtpsNo"
                                :disabled="disabledBtn"
                            ></Input>
                        </FormItem>
                    </iCol>
                    <iCol span="6">
                        <FormItem prop="corrEntryDclEtpsSccd">
                            <Input
                                size="small"
                                v-model="form.corrEntryDclEtpsSccd"
                                :maxlength="18"
                                placeholder="对应报关单申报单位社会信用代码"
                                :title="formErr.corrEntryDclEtpsSccd"
                                :disabled="disabledBtn"
                            ></Input>
                        </FormItem>
                    </iCol>
                    <iCol span="9">
                        <FormItem prop="corrEntryDclEtpsNm">
                            <Input
                                size="small"
                                v-model="form.corrEntryDclEtpsNm"
                                :disabled="disabledBtn"
                                placeholder="对应报关单申报单位名称"
                            ></Input>
                        </FormItem>
                    </iCol>

                </Row>
                <Row>
                    <iCol span="4">
                        <div class="form-label">关联报关单编号</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="rltEntryNo">
                            <Input size="small" v-model="form.rltEntryNo" disabled></Input>
                        </FormItem>
                    </iCol>
                    <iCol span="2">
                        <div class="form-label">关联清单编号</div>
                    </iCol>
                    <iCol span="6">
                        <FormItem prop="rltInvtNo">
                            <Input size="small" v-model="form.rltInvtNo" :disabled="disabledBtn"></Input>
                        </FormItem>
                    </iCol>
                    <iCol span="3">
                        <div class="form-label">关联手(账)册备案号</div>
                    </iCol>
                    <iCol span="6">
                        <FormItem prop="rltPutrecNo">
                            <Input size="small" v-model="form.rltPutrecNo" :disabled="disabledBtn"></Input>
                        </FormItem>
                    </iCol>
                </Row>
                <Row>
                    <iCol span="4">
                        <div class="form-label">关联报关单境内收发货人</div>
                    </iCol>
                    <iCol span="5">
                        <FormItem prop="rltEntryBizopEtpsno">
                            <Input
                                size="small"
                                v-model="form.rltEntryBizopEtpsno"
                                placeholder="关联报关单境内收发货人编码"
                                :maxlength="10"
                                :title="formErr.rltEntryBizopEtpsno"
                                :disabled="disabledBtn"
                            ></Input>
                        </FormItem>
                    </iCol>
                    <iCol span="6">
                        <FormItem prop="rltEntryBizopEtpssccd">
                            <Input
                                size="small"
                                v-model="form.rltEntryBizopEtpssccd"
                                :maxlength="18"
                                placeholder="关联报关单境内收发货人社会信用代码"
                                :title="formErr.rltEntryBizopEtpssccd"
                                :disabled="disabledBtn"
                            ></Input>
                        </FormItem>
                    </iCol>
                    <iCol span="9">
                        <FormItem prop="rltEntryBizopEtpsNm">
                            <Input
                                size="small"
                                v-model="form.rltEntryBizopEtpsNm"
                                placeholder="关联报关单境内收发货人名称"
                                :disabled="disabledBtn"
                            ></Input>
                        </FormItem>
                    </iCol>
                </Row>
                <Row>
                    <iCol span="4">
                        <div class="form-label">关联报关单{{form.impexpMarkcd === 'I' ? '消费使用' : '生产销售'}}单位</div>
                    </iCol>
                    <iCol span="5">
                        <FormItem prop="rltEntryRcvgdEtpsno">
                            <Input
                                size="small"
                                placeholder="关联报关单生产销售(消费使用)单位编码"
                                v-model="form.rltEntryRcvgdEtpsno"
                                :maxlength="10"
                                :title="formErr.rltEntryRcvgdEtpsno"
                                :disabled="disabledBtn"
                            ></Input>
                        </FormItem>
                    </iCol>
                    <iCol span="6">
                        <FormItem prop="rltEntryRvsngdEtpsSccd">
                            <Input
                                size="small"
                                v-model="form.rltEntryRvsngdEtpsSccd"
                                :maxlength="18"
                                placeholder="关联报关单生产销售(消费使用)社会信用代码"
                                :title="formErr.rltEntryRvsngdEtpsSccd"
                                :disabled="disabledBtn"
                            ></Input>
                        </FormItem>
                    </iCol>
                    <iCol span="9">
                        <FormItem prop="rltEntryRcvgdEtpsNm">
                            <Input
                                size="small"
                                v-model="form.rltEntryRcvgdEtpsNm"
                                :disabled="disabledBtn"
                                placeholder="关联报关单生产销售(消费使用)单位名称"
                            ></Input>
                        </FormItem>
                    </iCol>
                </Row>
                <Row>
                    <iCol span="4">
                        <div class="form-label">关联报关单申报单位</div>
                    </iCol>
                    <iCol span="5">
                        <FormItem prop="rltEntryDclEtpsno">
                            <Input
                                size="small"
                                v-model="form.rltEntryDclEtpsno"
                                :maxlength="10"
                                placeholder="关联报关单申报单位编码"
                                :title="formErr.rltEntryDclEtpsno"
                                :disabled="disabledBtn"
                            ></Input>
                        </FormItem>
                    </iCol>
                    <iCol span="6">
                        <FormItem prop="rltEntryDclEtpsSccd">
                            <Input
                                size="small"
                                v-model="form.rltEntryDclEtpsSccd"
                                :maxlength="18"
                                placeholder="关联报关单申报单位社会信用代码"
                                :title="formErr.rltEntryDclEtpsSccd"
                                :disabled="disabledBtn"
                            ></Input>
                        </FormItem>
                    </iCol>
                    <iCol span="9">
                        <FormItem prop="rltEntryDclEtpsNm">
                            <Input
                                size="small"
                                v-model="form.rltEntryDclEtpsNm"
                                placeholder="关联报关单申报单位名称"
                                :disabled="disabledBtn"
                            ></Input>
                        </FormItem>
                    </iCol>
                </Row>
                <Row>
                    <iCol span="4">
                        <div class="form-label">报关单申报日期</div>
                    </iCol>
                    <iCol span="3">
                        <FormItem prop="entryDclTime">
                            <Input size="small" v-model="form.entryDclTime" disabled></Input>
                        </FormItem>
                    </iCol>
                    <iCol span="2">
                        <div class="form-label">备注</div>
                    </iCol>
                    <iCol span="15">
                        <FormItem prop="rmk">
                            <Input size="small" v-model="form.rmk" @on-enter="handleRemarkEnter" :disabled="disabledBtn"></Input>
                        </FormItem>
                    </iCol>
                </Row>
                <Row>
                    <iCol span="4">
                        <div class="form-label">报关单草稿(备注)</div>
                    </iCol>
                    <iCol span="20">
                        <FormItem prop="decRmk">
                            <Input size="small" v-model="form.decRmk" disabled></Input>
                        </FormItem>
                    </iCol>
                </Row>
            </Form>
        </section>
        <cargoTable
            ref="cargoTable"
            :disabled="disabledBtn"
            :etpsNo="etpsNo"
            :ieFlag="form.impexpMarkcd"
            :templateType="templateType"
            @changeLen="handleCargoLenChange"
            @putrecSeqnoBlur="handlePutrecSeqnoBlur"
        ></cargoTable>
        <ImportModal
            v-model="importVisible"
            :refreshMethod="importSuccess"
            :templateList="templateList"
            :defautl-action="importXlsInvtUrl"
            :importParams="importParams"
        ></ImportModal>

        <perfectCompanyInfoModal ref="perfectCompanyInfoModalRef"/>
        <PrintModal
            title="打印核注清单"
            v-model="printModal.visible"
            :options="printModal.options"
            :queryFileFn="queryInvtFile"
        ></PrintModal>
        <Modal :width="600" v-model="errVisible" @on-visible-change="errVisibleChange">
            <div slot="header" class="ivu-modal-confirm-head">
                <div class="ivu-modal-confirm-head-icon ivu-modal-confirm-head-icon-error">
                    <Icon type="ios-close-circle"></Icon>
                </div>
                <div class="ivu-modal-confirm-head-title">请检查商品信息</div>
            </div>
            <Table
                :height="300"
                :data="errData"
                :columns="errColumns"
            ></Table>

        </Modal>
    </div>
</template>

<script>
import { mapMutations } from 'vuex'
import { nextFocus } from '@/libs/ivuDom'
import { on, throttle, debounce, trim } from '@/libs/tools'
import { getDicByKey } from '@/libs/getDicDataList'
import { queryCustomForCustGrid, queryCustom } from '@/api/customer'
import {
    invtBusType,
    IEType,
    MFProductMark,
    dclcusFlagType,
    dclcusTypecdType
} from '@/libs/customsOptions'
import { queryTemplateById } from '@/api/templet'
import { defInvtTemp } from '@/api/downloadTemp'
import {
    saveCheckReg,
    sendInvtToSingleWindow,
    importXlsInvtUrl,
    queryManualByItem,
    queryCheckRegById
} from '@/api/invt'

import checkRegMinix from './js/checkRegMinix'
import perfectCompanyInfoModal from './components/perfectCompanyInfoModal'
import cargoTable from './components/cargo-table'
import ImportModal from './components/import-modal'
import checkregError from './js/checkreg-error'
import getCheckregRules from './js/checkreg-rules'
import RemoteSearch from '@/view/components/RemoteSearch'
import { getBasicData } from '@/api/declare.js'

import printMixins from './js/print-mixins'

/**
 * 查询客户信息
 * @param {Object} params 搜索条件
 * @param {Function} cb 搜索成功回调函数
 */
function queryCustomerInfo (params, cb) {
    queryCustomForCustGrid(params).then(res => {
        if (res.data.code === '0000') {
            cb(res.data.data.list)
        }
    })
}
export default {
    name: 'InvtAdd',
    mixins: [
        checkRegMinix,
        printMixins
    ],
    components: {
        perfectCompanyInfoModal,
        ImportModal,
        cargoTable,
        RemoteSearch
    },
    data () {
        const formErr = checkregError()
        const rules = getCheckregRules((key, v) => {
            this.formErr[key] = v
        })
        return {
            disabledBtn: false,
            typeData: [],
            regionData: [],
            districtCodeList: [],
            customsCodeList: [], // 海关
            trafModeList: [], // 运输方式
            tradeModeList: [], // 监管方式
            etpsNo: '', // 货物商品明细组件的 企业内部编号
            importXlsInvtUrl, // 导入地址
            importVisible: false, // 导入弹窗显示状态
            importParams: {}, // 导入额外参数
            // 导入模板列表
            templateList: [{
                value: -1,
                label: '核注清单导入模板',
                url: defInvtTemp
            }],
            businessType: invtBusType, // 业务类型列表
            inOutType: IEType, // 进出口别列表
            MFProductMarkList: MFProductMark, // 料件、成品标志列表
            dclcusFlagType, // 报关标志
            dclcusTypecdType, // 报关类型
            form: {
                invtId: '', // 清单id
                custId: '', // 委托单位
                sysId: '', // 业务类型
                impexpMarkcd: '', // 进出口别
                seqNo: '', // 预录入统一编号
                bondInvtNo: '', // 清单编号
                invtType: '', // 清单类型
                putrecNo: '', // 手(账)册编号
                bizopEtpsId: '', // 经营单位id
                bizopEtpsno: '', // 经营单位编码
                bizopEtpsSccd: '', // 经营单位社会信用代码
                bizopEtpsNm: '', // 经营单位名称
                rvsngdEtpsId: '', // 加工单位id
                rcvgdEtpsno: '', // 加工单位编码
                rvsngdEtpsSccd: '', // 加工单位社会信用代码
                rcvgdEtpsNm: '', // 加工单位名称
                dclEtpsId: '', // 申报单位id
                dclEtpsno: '', // 申报单位编码
                dclEtpsSccd: '', // 申报单位社会信用代码
                dclEtpsNm: '', // 申报单位名称
                inputId: '', // 录入单位id
                inputCode: '', // 录入单位编码
                inputCreditCode: '', // 录入单位社会信用代码
                inputName: '', // 录入单位名称
                etpsInnerInvtNo: '', // 企业内部编号
                inputTime: '', // 录入日期
                invtDclTime: '', // 清单申报日期
                mtpckEndprdMarkcd: '', // 料件、成品标志
                supvModecd: '', // 监管方式
                trspModecd: '', // 运输方式
                impexpPortcd: '', // 进境关别
                dclPlcCuscd: '', // 主管海关
                vrfdedMarkcd: '', // 核扣标志代码
                vrfdedMarkcdName: '', // 核扣标志名
                stshipTrsarvNatcd: '', // 启运国(地区)
                invtIochkptStucd: '', // 清单进出卡口状态
                applyNo: '', // 申报表编号
                listType: '', // 流转类型
                dclcusFlag: '', // 报关标志
                dclcusTypecd: '', // 报关类型
                decType: '', // 报关单类型
                entryNo: '', // 对应报关单编号
                corrEntryDclEtpsNo: '', // 对应报关单申报单位编码
                corrEntryDclEtpsSccd: '', // 对应报关单申报单位社会信用代码
                corrEntryDclEtpsNm: '', // 对应报关单申报单位名称
                rltEntryNo: '', // 关联报关单编号
                rltInvtNo: '', // 关联清单编号
                rltPutrecNo: '', // 关联手(账)册备案号
                rltEntryBizopEtpsno: '', // 关联报关单境内收发货人编码
                rltEntryBizopEtpssccd: '', // 关联报关单境内收发货人社会信用代码
                rltEntryBizopEtpsNm: '', // 关联报关单境内收发货人名称
                rltEntryRcvgdEtpsno: '', // 关联报关单生产销售(消费使用)单位编码
                rltEntryRvsngdEtpsSccd: '', // 关联报关单生产销售(消费使用)社会信用代码
                rltEntryRcvgdEtpsNm: '', // 关联报关单生产销售(消费使用)单位名称
                rltEntryDclEtpsno: '', // 关联报关单申报单位编码
                rltEntryDclEtpsSccd: '', // 关联报关单申报单位社会信用代码
                rltEntryDclEtpsNm: '', // 关联报关单申报单位名称
                entryDclTime: '', // 报关单申报日期
                rmk: '', // 备注
                decRmk: '', // 报关单草稿(备注)
                holdFlag: '', // 发送暂存状态
                delcareFlag: '' // 发送申报状态
            },
            formErr,
            rules,
            cpLoading: false,
            sbLoading: false,
            sendLoading: false,
            sendType: 0,
            bizopList: [],
            rvsngdList: [],
            putrecList: [],
            custList: [], // 委托单位列表
            templateType: '',
            errColumns: [
                {
                    title: '项号',
                    key: 'index',
                    width: 50,
                    align: 'center'
                },
                {
                    title: '字段名称',
                    key: 'field',
                    align: 'center'
                },
                {
                    title: '错误信息',
                    key: 'msg',
                    align: 'center',
                    tooltip: true
                }
            ],
            errData: [],
            errVisible: false,
            disabledImpexpMarkcd: false // 是否禁止修改进出口别(TAPD:1007930)
        }
    },

    computed: {
        impexpPortcdLabel () {
            return this.form.impexpMarkcd === this.inOutType[0].value ? '出境关别' : ' 进境关别'
        },
        stshipTrsarvNatcdLabel () {
            return this.form.impexpMarkcd === this.inOutType[0].value ? '运抵国' : ' 启运国'
        }

    },
    created () {
        // 核注清单部分按钮增加节流函数 防止重复点击触发
        const delay = 350
        this.sendToSingleWindow = throttle(this.sendToSingleWindow, delay)
        this.submitSave = throttle(this.submitSave, delay)
        this.queryCustList()
        this.getTradeModeList()
        this.getTrafModeList()
        this.getCustomsCodeList()
        this.getRegionFn()
        this.getTypeFn()
    },
    mounted () {
        const id = this.$route.params.id
        if (id) {
            this.queryCheckRegDetail(id)
        } else {
            const { templateId } = this.$route.query
            if (templateId) {
                // 有模板则判断模板id是否与本地一致 不一致需要重新查询
                if (templateId !== this.templateId) {
                    this.queryTemplateDetail(templateId, data => {
                        this.initInvtData(data.CustomsInvtVo || {})
                    })
                }
            } else {
                // 没有模板则清空本地模板数据
                this.templateId = ''
                this.templateType = ''
            }
            this.checkInvtButtonStatus()
        }
        this.$nextTick(_ => {
            this.bindInputKeyupEnterEvent()
        })
    },
    methods: {
        // 清空核注清单页面数据
        clearInvtData () {
            this.templateId = ''
            this.templateType = ''
            Object.keys(this.form).forEach((key) => {
                this.form[key] = ''
            })
            this.$nextTick(() => {
                Object.keys(this.formErr).forEach((key) => {
                    this.formErr[key] = ''
                })
                this.$refs.baseForm.resetFields()
            })
            if (this.$refs.cargoTable) {
                this.$refs.cargoTable.initData([])
                this.$refs.cargoTable.setDefaultData()
            }
        },
        // 获取报关单类型

        getTypeFn () {
            return new Promise((resolve, reject) => {
                let data = {
                    dataMainType: 'INVT_DECTYPE',
                    pageNum: 1,
                    pageSize: 10000
                }
                getBasicData(data).then(res => {
                    this.typeData = res.data.data.list
                    resolve()
                }).catch(err => {
                    getRegionFn('INVT_DECTYPE')
                })
            })
        },
        // 启用国
        getRegionFn () {
            return new Promise((resolve, reject) => {
                let data = {
                    dataMainType: 'INVT_CONTY_REG',
                    pageNum: 1,
                    pageSize: 10000
                }
                getBasicData(data).then(res => {
                    this.regionData = res.data.data.list
                    resolve()
                }).catch(err => {
                    getRegionFn('INVT_CONTY_REG')
                })
            })
        },
        queryCustList () {
            queryCustom({ pageNum: 1, pageSize: 10000 }).then(res => {
                if (res.data.code === '0000') {
                    this.custList = res.data.data.list
                }
            })
        },
        // 获取海关关别
        getCustomsCodeList () {
            return getDicByKey('CUSTOMS_CODE').then(list => {
                this.customsCodeList = list
            })
        },
        // 获取运输方式
        getTrafModeList () {
            return getDicByKey('TRAF_MODE').then(list => {
                this.trafModeList = list
            })
        },
        // 获得监管方式
        getTradeModeList () {
            return getDicByKey('TRADE_MODE').then(list => {
                this.tradeModeList = list
            })
        },
        ...mapMutations(['removeTagNav']),
        openImportModal () {
            this.importVisible = true
            const practicalTrainingId = this.$route.params.trainingId
            this.importParams = practicalTrainingId ? { practicalTrainingId } : {}
        },
        // 导入成功回调
        importSuccess () {
            this.$router.push({
                name: 'checkReg'
            })
        },
        // 根据id查询模板内容信息
        queryTemplateDetail (templateId, cb) {
            this.templateId = templateId
            queryTemplateById(this.templateId).then(res => {
                if (res.data.code === '0000') {
                    if (!res.data.data) return
                    let { businessType, templateId, templateContent } = res.data.data
                    this.templateId = templateId
                    this.templateType = businessType
                    // 模板内容
                    templateContent = JSON.parse(templateContent)
                    this.$refs.cargoTable.setDefaultData(templateContent.CustomsInvtGoodsVo)
                    cb && cb(templateContent)
                } else {
                    this.$Message.error(res.data.msg)
                }
            })
        },
        // 查询核注清单信息
        queryCheckRegDetail (InvtId) {
            queryCheckRegById(InvtId).then(res => {
                if (res.data.code === '0000') {
                    const data = res.data.data
                    this.initInvtData(data)
                    // 如果有模板并且模板与本地不一致则查询模板信息
                    if (data.templateId && data.templateId !== this.templateId) {
                        this.queryTemplateDetail(data.templateId)
                    }
                    this.templateId = data.templateId
                    this.templateType = data.templateType
                }
            })
        },
        // 初始化核注清单页面数据
        initInvtData (data) {
            // 设置商品组件内部编号
            this.etpsNo = data.etpsInnerInvtNo || ''
            this.$refs.cargoTable && this.$refs.cargoTable.initData(data.invtGoodsVoList || [])
            // this.$nextTick(_ => {
            Object.keys(this.form).forEach(key => {
                this.form[key] = data[key] || ''
            })
            const vrfdedMarkcdList = {
                0: '未核扣',
                1: '预核扣',
                2: '已核扣',
                3: '已核销'
            }
            this.form.vrfdedMarkcdName = this.form.vrfdedMarkcd ? (vrfdedMarkcdList[this.form.vrfdedMarkcd] || '') : ''
            // })
        },
        // 保存核注清单成功回调
        saveInvtSuccess (id) {
            if (!this.$route.params.id) {
                this.removeTagNavList()
            }
            if (id != this.form.invtId) {
                let params = {
                    id
                }
                this.$router.replace({
                    name: 'invtEdit',
                    params
                })
            }
            this.form.invtId = id
            this.queryCheckRegDetail(id)
        },
        goBack () {
            this.removeTagNav(this.$route)
            this.$router.push({
                name: 'invtList'
            })
        },
        cancel () {
            this.goBack()
        },
        // 清除当前的标签
        removeTagNavList () {
            this.removeTagNav(this.$route)
        },
        // 复制整个核注清单
        copyInvt () {
            this.cpLoading = true
            const disabledKeys = [
                'invtId',
                'seqNo',
                'bondInvtNo',
                'etpsInnerInvtNo',
                'invtIochkptStucd',
                'entryNo',
                'vrfdedMarkcd',
                'vrfdedMarkcdName',
                'rltEntryNo',
                'entryDclTime',
                'applyNo',
                'rltInvtNo',
                'invtDclTime',
                'rltPutrecNo',
                'holdFlag',
                'delcareFlag',
                'rmk'
            ]
            disabledKeys.forEach(key => {
                this.form[key] = ''
            })
            // copy货物数据
            this.$refs.cargoTable.copyAllCargoData()
            this.$Message.success('复制成功，请手动保存数据')
            this.removeTagNavList()
            this.$nextTick(() => {
                this.$router.replace({
                    name: this.$route.name,
                    query: {
                        key: new Date().getTime()
                    }
                })
            })
            this.disabledBtn = false
            this.cpLoading = false
        },
        // 绑定表单回车切换input
        bindInputKeyupEnterEvent () {
            const formDom = document.getElementById('base_form')
            this.inputs = formDom.querySelectorAll('input[type=text]')
            const self = this
            on(formDom, 'keyup', function next (event) {
                if (event.keyCode === 13) {
                    nextFocus(event, self.inputs)
                }
            })
        },
        // 经营单位联想搜索
        handleSearchBizop: debounce(function (v, params, len, cb) {
            let value = trim(v)
            if (!value || value.length < len) {
                cb && cb([])
            } else {
                queryCustomerInfo({
                    pageNum: 1,
                    pageSize: 20,
                    ...params
                }, list => {
                    const data = list ? list.slice(0, 10).map(item => {
                        return {
                            operatorId: item.custId,
                            operatorName: item.custName,
                            operatorCode: item.customsCode,
                            coScc: item.socialCreditCode
                        }
                    }) : []
                    cb && cb(data)
                })
            }
        }, 200),
        handleBizopChange (data, key) {
            const keys = ['bizopEtpsno', 'bizopEtpsSccd', 'bizopEtpsNm']
            const flag = keys.every(k => {
                return !this.form[k] || k === key
            })
            if (flag && data) {
                const { operatorName, coScc, operatorCode, operatorId } = data
                const values = [operatorCode, coScc, operatorName]
                keys.forEach((k, index) => {
                    if (k !== key) {
                        this.form[k] = values[index]
                        this.$nextTick(() => {
                            this.baseValidateField(k)
                        })
                    }
                })
                this.form.bizopEtpsId = operatorId
            }
        },
        handleRcvgdChange (data, key) {
            const keys = ['rcvgdEtpsno', 'rvsngdEtpsSccd', 'rcvgdEtpsNm']
            const flag = keys.every(k => {
                return !this.form[k] || k === key
            })
            if (flag && data) {
                const { operatorName, coScc, operatorCode, operatorId } = data
                const values = [operatorCode, coScc, operatorName]
                keys.forEach((k, index) => {
                    if (k !== key) {
                        this.form[k] = values[index]
                        this.$nextTick(() => {
                            this.baseValidateField(k)
                        })
                    }
                })
                this.form.rvsngdEtpsId = operatorId
            }
        },
        handleSearchBizopCode (v, cb) {
            this.handleSearchBizop(v, { customsCode: v }, 5, cb)
        },
        handleSearchBizopCoScc (v, cb) {
            this.handleSearchBizop(v, { socialCreditCode: v }, 5, cb)
        },
        handleSearchBizopName (v, cb) {
            this.handleSearchBizop(v, { custName: v }, 3, cb)
        },
        /**
         * 处理日期改变
         * @params {String} value 选中的日期
         * @params {String} key 对应form中的key值
         */
        handleDateChange (value, key) {
            this.form[key] = `${value} 08:00:00`
        },
        // 处理备注回车事件
        handleRemarkEnter () {
            this.$nextTick(_ => {
                // 调用cargoTable 组件的默认选中方法
                this.$refs.cargoTable.defaultFocus()
            })
        },
        // 校验基本信息表单某个字段
        baseValidateField (field) {
            this.$refs.baseForm && this.$refs.baseForm.validateField(field)
        },
        // 校验所有表单数据
        validateForms () {
            return Promise.all([this.$refs.baseForm.validate(), this.$refs.cargoTable.validate()]).then(res => {
                if (Object.prototype.toString.call(res[1]) === '[object Array]') {
                    this.openGoodsErrModal(res[1])
                }
                if (res[0] === false) {
                    this.$Message.error('请检查表头红框区域的字段')
                } if (res[1] === false) {
                    this.$Message.error('请保存编辑中的货物明细')
                }
                return res.every(item => item === true)
            })
        },
        // 获取待提交的数据
        getInvtData () {
            let data = {}
            Object.keys(this.form).forEach(key => {
                data[key] = this.form[key] === undefined ? '' : this.form[key]
            })

            data.seqNo = null
            data.bondInvtNo = null
            data.invtIochkptStucd = null
            data.entryNo = null
            data.vrfdedMarkcd = null
            data.vrfdedMarkcdName = null
            data.rltEntryNo = null
            data.entryDclTime = null
            data.decRmk = null
            data.holdFlag = null
            data.delcareFlag = null

            // 添加模板类型
            if (this.templateId) {
                data.templateId = this.templateId
                data.templateType = this.templateType
            }

            data.invtGoodsVoList = this.$refs.cargoTable.getData()
            data.practicalTrainingId = this.$route.params.trainingId
            return data
        },
        // 保存数据
        submitSave () {
            this.sbLoading = true
            this.validateForms().then(valid => {
                if (valid) {
                    saveCheckReg(this.getInvtData()).then(async res => {
                        if (res.data.code === '0000') {
                            if (res.data.data) {
                                this.saveInvtSuccess(res.data.data)
                            }
                            this.$Message.success(res.data.msg)
                        } else {
                            this.handleSaveError(res)
                        }
                        this.sbLoading = false
                    }).catch(err => {
                        this.sbLoading = false
                    })
                } else {
                    this.sbLoading = false
                }
            })
        },
        // 处理保存失败
        handleSaveError (res) {
            if (res.data.code === '1011') {
                this.$Modal.error({
                    title: '库存校验错误',
                    width: '600px',
                    render (h) {
                        return h('Table', {
                            style: {
                                width: '100%'
                            },
                            props: {
                                columns: [
                                    {
                                        title: '仓库商品料号',
                                        key: 'ckGdsMtno',
                                        width: 160,
                                        align: 'center',
                                        tooltip: true
                                    },
                                    {
                                        title: '项号',
                                        key: 'goodsIndex',
                                        width: 50,
                                        align: 'center'
                                    },
                                    {
                                        title: '错误信息',
                                        key: 'message',
                                        align: 'center',
                                        tooltip: true
                                    }
                                ],
                                data: res.data.data || []
                            }
                        })
                    }
                })
            } else {
                this.$Message.error(res.data.msg)
            }
        },
        // 保存并提交单一窗口
        sendToSingleWindow (type) {
            this.sendLoading = true
            this.sendType = type
            const sendName = type ? '申报单一窗口' : '导入单一窗口'
            this.validateForms().then(async valid => {
                if (valid) {
                    try {
                        const saveRes = await saveCheckReg(this.getInvtData())
                        if (saveRes.data.code === '0000') {
                            const InvtId = saveRes.data.data
                            this.form.invtId = InvtId
                            const sendRes = await sendInvtToSingleWindow(InvtId, type)
                            this.saveInvtSuccess(InvtId)
                            if (sendRes.data.code === '0000') {
                                if (sendRes.data.data.failNum > 0) {
                                    this.$Message.warning(`${sendName}失败！`)
                                } else {
                                    this.$Message.success(`${sendName}成功！`)
                                }
                            } else if (sendRes.data.code == '1010') {
                                this.$refs.perfectCompanyInfoModalRef.init()
                            } else {
                                this.$Message.warning(sendRes.data.msg || `${sendName}失败！`)
                                this.$router.push({
                                    name: 'invtEdit',
                                    query: {
                                        id: InvtId
                                    }
                                })
                            }
                            this.sendLoading = false
                        } else {
                            this.handleSaveError(saveRes)
                            this.sendLoading = false
                        }
                    } catch (err) {
                        this.sendLoading = false
                        console.log(err)
                    }
                } else {
                    this.sendLoading = false
                }
            })
        },
        // 导入并申报到单一窗口
        // 核注清单申报增加二次确认(TAPD_BUG:1020585)
        // 核注清单二次导入/申报提示(TAPD:1006776)
        confirmSendSingleWindow (v) {
            const flag = v == 1 // 判断是申报还是导入
            const status = flag ? this.form.delcareFlag : this.form.holdFlag // 获取申报|导入的状态
            if (flag || status) {
                const type = flag ? '申报' : '导入'
                const title = `${status ? '再次' : '确认'}${type}`
                const content = status
                    ? `核注清单已经被${type}过，再次${type}可能会导致回执异常，请确认是否继续${type}？`
                    : `是否${type}核注清单？`
                this.$Modal.confirm({
                    title: title,
                    content: content,
                    onOk: () => {
                        this.sendToSingleWindow(v)
                    }
                })
            } else {
                this.sendToSingleWindow(v)
            }
        },
        // 手册账号回车
        handleBlurPutrec (v) {
            this.$nextTick(() => {
                const value = trim(this.form.putrecNo || '')
                if (!this.form.impexpMarkcd || !value || value.length < 5) return
                queryManualByItem({
                    gmark: this.form.impexpMarkcd,
                    manualNo: value,
                    queryType: 'H'
                }).then(res => {
                    if (res.data.code === '0000') {
                        const data = res.data.data.customsManual && res.data.data.customsManual[0] || ''
                        if (data) {
                            this.form.putrecNo = data.manualNo
                        }
                    }
                })
            })
        },
        // 处理表体 商品信息 商品料号 + 表头手册账号带出商品信息
        handlePutrecSeqnoBlur (v, cb) {
            if (!this.form.impexpMarkcd || !this.form.putrecNo || this.form.putrecNo.length != 12 || !v) return
            queryManualByItem({
                gmark: this.form.impexpMarkcd,
                manualNo: this.form.putrecNo,
                itemNo: v,
                queryType: 'E'
            }).then(cb)
        },
        openGoodsErrModal (data) {
            this.errData = data
            this.errVisible = true
        },
        errVisibleChange (v) {
            if (!v) this.errData = []
        },
        // 校验核注清单按钮是否可用
        checkInvtButtonStatus (id) {
            const delcareFlag = this.form.delcareFlag
            this.disabledBtn = !!delcareFlag
        },
        handleCargoLenChange (v) {
            this.disabledImpexpMarkcd = v > 0
        },
        // 表体有商品信息的时候禁止修改类别,并提示(TAPD:1007929)
        handleImpexpMarkcdClick () {
            if (!this.disabledBtn && this.disabledImpexpMarkcd) {
                this.$Message.warning('不能修改，请先删除表体商品项')
            }
        }
    }
}
</script>

<style lang='less' scoped>
.checkreg-page {
    .declare-form {
        margin-top: 10px;
    }
    .form-title {
        color: #1291cc;
    }
    .addcargo {
        text-align: right;
        margin-bottom: 10px;
        .form-title {
            float: left;
        }
    }
    .form-btns {
        text-align: center;
        button + button {
            margin-left: 8px;
        }
    }
}
</style>
